﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GSLMS.Entity;
using GSLMS.Core;


namespace GSLMS.WebAPP.Areas.RiskAudit.Controllers.AuditCon.AuditConAdu
{
    public class AuditConAduController : AdminBaseController
    {
        protected override string navTabId
        {
            get { return "RiskAudit_AuditCon_AuditConAdu"; }
        }

        [HttpGet]
        public ActionResult Index()
        {
            var searchParam = new TB_ADU_CONARR();
            searchParam.STATUS = 1;
            searchParam.ConAduBy = CurentUser.UserName;
            searchParam.ConAduID = CurentUser.CurrentUserInfo.ID;
            var model = serviceAduConArr.GetConAduList(searchParam);
            ViewData["RowCount"] = searchParam.RowCount;

            ViewData["SearchParma"] = searchParam;
            InitSelect();
            return View(model);
        }

        [HttpPost]
        public ActionResult Index(FormCollection form)
        {
            var searchParam = base.SearchPara<TB_ADU_CONARR>(form, new TB_ADU_CONARR());
            searchParam.ConAduBy = CurentUser.UserName;
            searchParam.ConAduID = CurentUser.CurrentUserInfo.ID;
            var model = serviceAduConArr.GetConAduList(searchParam);
            ViewData["RowCount"] = searchParam.RowCount;
            InitSelect();
            return View(model);
        }

        protected void InitSelect()
        {
            ViewData["systemID"] = EnumHelper.ToSelectList<GSLMS.Entity.Enum.ApplyEnum.RegSystemID>();
        }



        public ActionResult Create(long id, int conaduflag)
        {
           
            var model = serviceProInfo.GetByID(id);
            ViewData["ConAduFlag"] = conaduflag;
            ViewData["FinalApprover"] = new SelectList(serviceEmp.GetUserPrivEffList("", ""), "username", "empname");
            ViewData["AuditInfo"] = serviceAppAudit.GetRiskAuditConAduAuditInfo(id);
            return View(model);
        }

        [HttpPost]
        public string CreateConAdu(FormCollection form)
        {
            string result = string.Empty;
            var model = new GSLMS.Entity.TB_ADU_CONADU();

            model.ID = 0;
            model.OPINION = Request["AuditContent"];
            model.ADURESULT = GSLMS.Core.Helper.ToInt(Request["hidActiondo"]);
            model.AUDITBY = CurentUser.UserName;
            model.ARRID = 0;//存储过程中通过proid取
            model.AUDITTIME =DateTime.Now;
            model.PROID = GSLMS.Core.Helper.ToLong(Request["id"]);
           



            try
            {
                if (serviceAduConAdu.Add(model))
                { result = AjaxResultSucess; }
                else
                { result = AjaxResultFail; }
            }
            catch (Exception ex)
            {
                base.ExceptionHand(ex);
                result = AjaxResultFail;
            }

            return "{" + result + "}";
        }

    }
}
